import SessionUtil from '../../../data/session/session'
var a = '../../images/radio-checked.png';
var b = '../../images/radio.png'
Page({
    data: {
        token: '',
        isExpress: 'active',
        isSince: '',
        imgRadio1: a,
        imgRadio2: b,
        dilivery: '快递'
    },
    onLoad: function (options) {
        getApp().getSaleMode()
        SessionUtil.getInstance().then(session=>{
            let delivery = options.dilivery ? options.dilivery : this.data.dilivery
            this.setData({
                token: session.token,
                dilivery: delivery
            });
            if (delivery != '快递') {
                this.setData({
                    imgRadio1: b,
                    imgRadio2: a,
                });
            }
            wx.setNavigationBarTitle({
                title: '送货方式'
            })
        })        
    },

    switchDilivery: function (e) {
        var dilivery = e.currentTarget.id;
        var pages = getCurrentPages();
        var prevPage = pages[pages.length - 2]; //上一个页面
        var page = this;
        page.setData({
            imgRadio1: page.data.imgRadio2,
            imgRadio2: page.data.imgRadio1
        });
        var deliveryId = 0;
        if (dilivery == '自提') {
                deliveryId= 999999999
        } else if (dilivery == '快递') {
                deliveryId= 2
        }
        prevPage.setData({
            dilivery: dilivery,
            deliveryId: deliveryId
        })
        wx.navigateBack();
    },

    onPullDownRefresh: function () {
        wx.stopPullDownRefresh()
    },
})
